home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-03-23 | 26.8 KB | 725 lines | [TEXT/EMAC] |
- ;;;
- ;;; Implementation of the THINK Editor suite
- ;;;
- ;;; This file is part of the Macintosh port of GNU Emacs.
- ;;; Copyright (C) 1993 Marc Parmet.
- ;;;
-
-
- ; Events Sent From THINK To The Editor
- ; ====================================
- ;
- ; Open Document --- THINK sends this event when it wants the editor to open a text file.
- ;
- ; Event Class: kCoreEventClass
- ; Event ID: kAEOpenDocuments
- ; Parameters:
- ;
- ; keyDirectObject (typeFSS, required)
- ; The file to open.
- ;
- ; keyAEPosition (typeChar, optional)
- ; A struct which may specify a selection range and/or accompanying error message.
- ; The struct is defined as follows:
- ;
- ; struct {
- ; short showMsg; // if nonzero and line >= 0, display errmsg in an Alert.
- ; short line; // The line to be selected.
- ; long start; // The start of the selection range (ignore if line>=0).
- ; long end; // The end of the selection range (ignore if line>=0).
- ; StringHandle errmsg; // The error message to display.
- ; long fileModDate; // The modification time of the disk file.
- ; };
- ;
- ; If line, start, and end are all negative, there is no selection range specified.
- ; Otherwise, the selection range indicated by line or start/end should be selected
- ; and the edit window should be scrolled to show this selection.
- ;
- ; If line>=0 and showMsg is nonzero, the error message at *errmsg should be
- ; displayed immediately after selecting and scrolling to the line.
-
- (c:defstruct tc:struct-position ((short showMsg)
- (short line)
- (long start)
- (long end)
- (long errMsg)
- (long fileModDate)))
-
- ;;; This is called by the general OpenDocuments handler, which has special knowledge
- ;;; of this routine.
- (defun tc:parse-position-record (event)
- (if tc:debug-trace (DebugStr "Emacs TPM code got ODOC event"))
- (condition-case errmsg
- (catch 'panic
- (let* ((returnedType (make-string 4 0))
- (data (make-string (c:sizeof 'tc:struct-position) 0))
- (actualSize (make-string 4 0))
- (junk (throw-err
- (AEGetParamPtr event keyAEPosition typeChar returnedType
- data (length data) actualSize)))
- (showMsg (c:slotref 'tc:struct-position data 'showMsg))
- (line (1+ (c:slotref 'tc:struct-position data 'line)))
- (start (1+ (c:slotref 'tc:struct-position data 'start)))
- (end (1+ (c:slotref 'tc:struct-position data 'end)))
- (errMsg-handle (c:slotref 'tc:struct-position data 'errMsg)))
- (setq tc:opened-from-TPM t)
- (if (>= line 1)
- (goto-line line)
- (if (and (>= start 1) (>= end 1))
- (progn
- (goto-char start)
- (set-mark end)
- (if (not (input-pending-p))
- (progn
- (sit-for 1)
- (goto-char end)
- (if (not (input-pending-p))
- (sit-for 1))
- (goto-char start))))))
- (if (and (not (zerop showMsg))
- (>= line 0))
- (progn
- (HLock errMsg-handle)
- (let ((errMsg-ptr (deref errMsg-handle)))
- (message (concat "TPM message: "
- (extract-internal errMsg-ptr 0 'pascal-string))))
- (HUnlock errMsg-handle)))
- (bring-emacs-to-the-front)))
- (error (if tc:debug-failures (DebugStr "Couldn't complete ODOC"))
- errAEEventNotHandled)))
-
- ; -----------------------------------------------------------------------
- ; -----------------------------------------------------------------------
- ;
- ; Modified --- THINK sends the Modified event when it needs to know which files have been
- ; modified and when they've been modified. Send back a list of the following
- ; structs as the direct object of the reply event (one struct for each open
- ; file that has been modified).
- ;
- ; Event Class: 'KAHL'
- ; Event ID: 'MOD '
- ; Parameters: none
- ;
- ; struct {
- ; FSSpec fss; // the file spec
- ; long when; // the time the file was last modified
- ; short saved; // ??? when replying to the Modified event, set 'saved' to zero
- ; };
-
- (AEInstallEventHandler "KAHL" "MOD " 'tc:do-modified-event 0 0)
-
- (c:defstruct tc:struct-modified ((FSSpec fss)
- (long when)
- (short saved)))
-
- (defun tc:do-modified-event (event reply refCon)
- (if tc:debug-trace (DebugStr "Emacs TPM code got MOD event"))
- (condition-case errmsg
- (catch 'panic
- (let* ((file-list (tc:relevant-buffers))
- (ae-list (make-string sizeof-AEDescList 0))
- now
- spec
- (modified-record (make-string (c:sizeof 'tc:struct-modified) 0)))
- ;(DebugStr "In do-mod, file-list is " file-list)
- (throw-err (AECreateList 0 0 0 ae-list))
- (GetDateTime now)
- (while file-list
- (if (and (nth 1 (car file-list)) ; File name associated with buffer
- (nth 2 (car file-list))) ; Buffer modified since last save
- (progn
- ;(DebugStr "Looking at " (nth 1 (car file-list)))
- (throw-err (unix-filename-to-FSSpec (nth 1 (car file-list)) spec))
- (c:slotset 'tc:struct-modified modified-record 'fss spec)
- (c:slotset 'tc:struct-modified modified-record 'when (- now 5))
- (c:slotset 'tc:struct-modified modified-record 'saved 0)
- (throw-err (AEPutPtr ae-list 0 typeChar modified-record
- (length modified-record)))))
- (setq file-list (cdr file-list)))
- ;(DebugStr "In do-mod, adding direct obj")
- (throw-err (AEPutParamDesc reply keyDirectObject ae-list))
- noErr))
- (error (if tc:debug-failures (DebugStr "Couldn't complete MOD"))
- errAEEventNotHandled)))
-
- ; -----------------------------------------------------------------------
- ; -----------------------------------------------------------------------
- ;
- ; Get Text --- THINK sends this event when it needs to get a current copy of the file
- ; (for compilation or debugging).
- ;
- ; Event Class: 'KAHL'
- ; Event ID: 'GTTX'
- ; Parameters:
- ;
- ; keyDirectObject (typeChar, required)
- ; A struct which specifies the file THINK is looking for, and where the editor
- ; should return the requested information.
- ;
- ; struct {
- ; FSSpec fss; // the file THINK is looking for
- ; Handle textH; // where to return the file's text
- ; FTRec *ftp; // where to return the font/tabs info
- ; // (ftp == 0 if compiling). This info is used to format
- ; // the file's display in the Debugger's Source window.
- ; long *modified; // where to return the time-modified of the file
- ; };
-
- (AEInstallEventHandler "KAHL" "GTTX" 'tc:do-gttx-event 0 0)
-
- (c:defstruct tc:struct-gttx ((FSSpec fss)
- (long textH)
- (long ftp)
- (long modified)))
-
- (c:defstruct tc:struct-FTRec ((short fontNum)
- (short fontSize)
- (short spaceWidth)
- (short tabStops)))
-
- (defun tc:do-gttx-event (event reply refCon)
- (if tc:debug-trace (DebugStr "Emacs TPM code got GTTX event"))
- (condition-case errmsg
- (catch 'panic
- (let* ((returnedType (make-string 4 0))
- (actualSize (make-string 4 0))
- (gttx-msg (make-string (c:sizeof 'tc:struct-gttx) 0))
- now
- (junk1 (throw-err
- (AEGetParamPtr event keyDirectObject typeChar returnedType
- gttx-msg (c:sizeof 'tc:struct-gttx) actualSize)))
- (spec (c:slotref 'tc:struct-gttx gttx-msg 'fss))
- (textH (c:slotref 'tc:struct-gttx gttx-msg 'textH))
- (ftp (c:slotref 'tc:struct-gttx gttx-msg 'ftp))
- (modified (c:slotref 'tc:struct-gttx gttx-msg 'modified))
- (filename (FSSpec-to-unix-filename spec))
- (junk2 (if (integerp filename) (throw 'panic filename)))
- (old-buffer (current-buffer))
- (buffer (get-file-buffer filename)))
- (if (not buffer) (throw 'panic errAEEventNotHandled))
- (set-buffer buffer)
- (SetHandleSize textH (buffer-size))
- (if (not (zerop (MemError))) (throw 'panic (MemError)))
- (if tc:debug-trace (DebugStr "Moving " (buffer-size) " bytes to " textH))
- (subst-char-in-region (point-min) (point-max) 10 13 t)
- (HLock textH)
- (BlockMove (buffer-string) (StripAddress (deref textH)) (buffer-size))
- (HUnlock textH)
- (subst-char-in-region (point-min) (point-max) 13 10 t)
-
- (if (not (zerop ftp))
- (progn
- (if tc:debug-trace (DebugStr "Filling in ftp record"))
- (tc:send-mkup buffer)
- (if (not (zerop (tc:lineOffsets)))
- (progn (DisposHandle (tc:lineOffsets)) (setf-tc:lineOffsets 0)))
- (remake-lineOffsets)
- ;;; Need more accurate values here.
- (c:slotset 'tc:struct-FTRec ftp 'fontNum 4)
- (c:slotset 'tc:struct-FTRec ftp 'fontSize 9)
- (c:slotset 'tc:struct-FTRec ftp 'spaceWidth 6)
- (c:slotset 'tc:struct-FTRec ftp 'tabStops tab-width)))
-
- (GetDateTime now)
- (encode-internal modified 0 'long (if (buffer-modified-p) (- now 5) 0))
- (set-buffer old-buffer)
- noErr))
- (error (if tc:debug-failures (DebugStr "Couldn't complete GTTX"))
- errAEEventNotHandled)))
-
- ; -----------------------------------------------------------------------
- ; -----------------------------------------------------------------------
- ;
- ; Get Debugger State --- THINK sends this event when it needs to get the current Debugger
- ; state information for the file (when debugging).
- ;
- ; Event Class: 'KAHL'
- ; Event ID: 'GTDS'
- ; Parameters:
- ;
- ; keyDirectObject (typeChar, required)
- ; A struct which indicates the file THINK is looking for, the type of information
- ; THINK wants, and where the editor should return the requested information.
- ; Refer to the MiniEdit source code to see how to access and return the data.
- ;
- ; typedef struct {
- ; short fileNum; /* for THINK's internal use */
- ; long rsrcType; /* 'BKPT' or 'DTVU' */
- ; short rsrcID; /* ID of desired resource */
- ; void *rsrcH; /* Handle to resource data */
- ; } getStateMsg;
- ;
- ; struct {
- ; FSSpec fss; // The file of interest
- ; getStateMsg *msg;
- ; };
-
- (c:defstruct tc:struct-fssPlus ((FSSpec fss)
- (long getStateMsg)))
-
- (c:defstruct tc:struct-getStateMsg ((short fileNum)
- ((array char 4) rsrcType)
- (short rsrcID)
- (long rsrcH)))
-
- (AEInstallEventHandler "KAHL" "GTDS" 'tc:do-gtds-event 0 0)
-
- (defun tc:do-gtds-event (event reply refCon)
- (if tc:debug-trace (DebugStr "Emacs TPM code got GTDS event"))
- (condition-case errmsg
- (catch 'panic
- (let* ((resultType (make-string 4 0))
- (data (make-string (c:sizeof 'tc:struct-fssPlus) 0))
- (actualSize (make-string 4 0))
- (junk (throw-err (AEGetParamPtr event keyDirectObject typeChar resultType
- data (length data) actualSize)))
- (spec (c:slotref 'tc:struct-fssPlus data 'fss))
- (msg (c:slotref 'tc:struct-fssPlus data 'getStateMsg))
- (rsrcType (c:slotref 'tc:struct-getStateMsg msg 'rsrcType))
- (rsrcID (c:slotref 'tc:struct-getStateMsg msg 'rsrcID))
- (filename (FSSpec-to-unix-filename spec))
- (old-buffer (current-buffer))
- (buffer (get-file-buffer filename)))
- (if (not buffer) (throw 'panic errAEEventNotHandled))
- (if tc:debug-trace (DebugStr "Resource type is " rsrcType " " rsrcID))
- (set-buffer buffer)
- (if (not tc:have-TPM-data) (throw 'panic errAEEventNotHandled))
- (let ((dataHandle
- (cond
- ((equal rsrcType "DTVU")
- (find-rsrc (tc:dataviews) (tc:dtvuIDs) (tc:dtvuSizes)))
- ((equal rsrcType "BKPT")
- (find-rsrc (tc:breakpoints) (tc:bkptIDs) (tc:bkptSizes)))
- (t
- (throw 'panic errAEEventNotHandled)))))
- (set-buffer old-buffer)
- (c:slotset 'tc:struct-getStateMsg msg 'rsrcH dataHandle)
- noErr)))
- (error (if tc:debug-failures (DebugStr "Couldn't complete GTDS"))
- errAEEventNotHandled)))
-
- (defun find-rsrc (data IDs sizes)
- (if (or (zerop data) (zerop IDs) (zerop sizes))
- (throw 'panic errAEEventNotHandled))
- (let* ((numIDs (/ (GetHandleSize IDs) (c:sizeof 'long)))
- (rsrcIndex (lookup-rsrc-id IDs numIDs rsrcID))
- (junk (if (not rsrcIndex) (throw 'panic errAEEventNotHandled)))
- (thisSize (extract-internal (deref sizes) (* (c:sizeof 'long) rsrcIndex) 'long))
- (offset (sum-sizes sizes rsrcIndex))
- (dataHandle (NewHandle thisSize))
- (err (MemError)))
- (if (not (zerop err)) (throw 'panic err))
- (HLock dataHandle)
- (BlockMove (+ (deref data) offset) (deref dataHandle) thisSize)
- (HUnlock dataHandle)
- dataHandle))
-
- (defun sum-sizes (size-list target-index)
- (let ((i 0)
- (sum 0))
- (while (< i target-index)
- (setq sum (+ sum (extract-internal (deref size-list) (* (c:sizeof 'long) i) 'long)))
- (setq i (1+ i)))
- sum))
-
- (defun lookup-rsrc-id (id-list numIDs targetID)
- (let ((i 0)
- (result nil))
- (while (< i numIDs)
- (let ((thisID (extract-internal (deref id-list) (* (c:sizeof 'long) i) 'long)))
- (if tc:debug-trace (DebugStr "Comparing " thisID " and " targetID))
- (if (= thisID targetID)
- (progn
- (setq result i)
- (setq i numIDs))
- (setq i (1+ i)))))
- result))
-
- ; -----------------------------------------------------------------------
- ; -----------------------------------------------------------------------
- ;
- ; Put Debugger State --- THINK sends this event when it needs to replace the Debugger state
- ; info for a file (when the THINK Debugger saves its current state).
- ; To respond to this event, the editor returns pointers to its
- ; Debugger state info Handles (among other things) in the struct
- ; type defined below.
- ;
- ; Event Class: 'KAHL'
- ; Event ID: 'PTDS'
- ; Parameters:
- ;
- ; keyDirectObject (typeChar, required)
- ; A struct which indicates the file THINK is looking for, and where the editor
- ; should return the requested information. See the MiniEdit source code for more
- ; details.
- ;
- ; struct {
- ; FSSpec fss;
- ; long ****pBkptIDs;
- ; long ****pDtvuIDs;
- ; long ****pBkptSizes;
- ; long ****pDtvuSizes;
- ; Handle **pMarkers;
- ; Handle **pBreakpoints;
- ; Handle **pDataviews;
- ; short ****pLineOffsets;
- ; long (**GetCharPos)(TEHandle, long);
- ; short (**GetLineNum)(TEHandle, long, long*);
- ; long *oldSelStart, *oldSelEnd, *oldTextLength,
- ; *oldLineStart, *oldLineEnd, *oldNumLines,
- ; *newTextLength, *newNumLines, *newSelEnd,
- ; *refcon;
- ; };
-
- (c:defstruct tc:struct-ptds ((FSSpec fss)
- (long pBkptIDs)
- (long pDtvuIDs)
- (long pBkptSizes)
- (long pDtvuSizes)
- (long pMarkers)
- (long pBreakpoints)
- (long pDataviews)
- (long pLineOffsets)
- (long GetCharPos)
- (long GetLineNum)
- (long oldSelStart)
- (long oldSelEnd)
- (long oldTextLen)
- (long oldLineStart)
- (long oldLineEnd)
- (long oldNumLines)
- (long newTextLen)
- (long newNumLines)
- (long newSelEnd)
- (unsigned-long refCon)))
-
- (AEInstallEventHandler "KAHL" "PTDS" 'tc:do-ptds-event 0 0)
-
- (defun tc:do-ptds-event (event reply refCon)
- (if tc:debug-trace (DebugStr "Emacs TPM code got PTDS event"))
- (condition-case errmsg
- (catch 'panic
- (let* ((resultType (make-string 4 0))
- (data (make-string (c:sizeof 'tc:struct-ptds) 0))
- (actualSize (make-string 4 0))
- (junk (throw-err (AEGetParamPtr event keyDirectObject typeChar resultType
- data (length data) actualSize)))
- (spec (c:slotref 'tc:struct-ptds data 'fss))
- (filename (FSSpec-to-unix-filename spec))
- (old-buffer (current-buffer))
- (buffer (get-file-buffer filename)))
- (if tc:debug-trace (DebugStr "ptds data is at " (string-data data)
- ", buffer is " buffer))
- (if (not buffer) (throw 'panic errAEEventNotHandled))
- (set-buffer buffer)
- (if (zerop tc:addressables) (throw 'panic errAEEventNotHandled))
-
- (mapcar (function (lambda (x)
- (encode-internal
- (c:slotref 'tc:struct-ptds data (car x))
- 0 'unsigned-long (cdr x))))
- (list
- (cons 'pBkptIDs (+ tc:addressables tc:bkptIDs-offset))
- (cons 'pDtvuIDs (+ tc:addressables tc:dtvuIDs-offset))
- (cons 'pBkptSizes (+ tc:addressables tc:bkptSizes-offset))
- (cons 'pDtvuSizes (+ tc:addressables tc:dtvuSizes-offset))
- (cons 'pMarkers (+ tc:addressables tc:markers-offset))
- (cons 'pBreakpoints (+ tc:addressables tc:breakpoints-offset))
- (cons 'pDataviews (+ tc:addressables tc:dataviews-offset))
- (cons 'pLineOffsets (+ tc:addressables tc:lineOffsets-offset))
- (cons 'GetCharPos tc:GetCharPos)
- (cons 'GetLineNum tc:GetLineNum)
- (cons 'oldSelStart tc:oldSelStart)
- (cons 'oldSelEnd tc:oldSelEnd)
- (cons 'oldTextLen tc:oldTextLen)
- (cons 'oldLineStart tc:oldLineStart)
- (cons 'oldLineEnd tc:oldLineEnd)
- (cons 'oldNumLines tc:oldNumLines)
- (cons 'newTextLen (tc:textLen))
- (cons 'newNumLines (tc:numLines))
- (cons 'newSelEnd (tc:selEnd))
- (cons 'refCon buffer)))
- (set-buffer old-buffer)
- noErr))
- (error (if tc:debug-failures (DebugStr "Couldn't complete PTDS"))
- errAEEventNotHandled)))
-
- ; -----------------------------------------------------------------------
- ; -----------------------------------------------------------------------
- ;
- ; Window Search --- THINK sends this event whenever it needs to know whether the editor
- ; has a specific file open for editing. If the file is open, send back
- ; the file's modified time; otherwise, return fnfErr (file not found).
- ;
- ; Event Class: 'KAHL'
- ; Event ID: 'SRCH'
- ; Parameters:
- ;
- ; keyDirectObject (typeChar, required)
- ; A struct which indicates the file THINK is looking for, and where the editor
- ; should return the file's modified time. See the MiniEdit source code for more
- ; details.
- ;
- ; struct {
- ; FSSpec fss; // The file THINK is looking for.
- ; long *modified; // Where to return the file's modified time.
- ; };
-
- (AEInstallEventHandler "KAHL" "SRCH" 'tc:do-srch-event 0 0)
-
- (c:defstruct tc:struct-srch ((FSSpec fss)
- (long modified)))
-
- (defun tc:do-srch-event (event reply refCon)
- (if tc:debug-trace (DebugStr "Emacs TPM code got SRCH event"))
- (condition-case errmsg
- (catch 'panic
- (let* ((returnedType (make-string 4 0))
- (actualSize (make-string 4 0))
- (srch-record (make-string (c:sizeof 'tc:struct-srch) 0))
- now
- (junk (throw-err
- (AEGetParamPtr event keyDirectObject typeChar returnedType
- srch-record (c:sizeof 'tc:struct-srch) actualSize)))
- (spec (c:slotref 'tc:struct-srch srch-record 'fss))
- (modified (c:slotref 'tc:struct-srch srch-record 'modified))
- (filename (FSSpec-to-unix-filename spec))
- (buffer (get-file-buffer filename)))
- (if (not buffer) (throw 'panic fnfErr))
- (set-buffer buffer)
- (GetDateTime now)
- (encode-internal modified 0 'long (if (buffer-modified-p) (- now 5) 0))
- noErr))
- (error (if tc:debug-failures (DebugStr "Couldn't complete SRCH"))
- errAEEventNotHandled)))
-
- ; -----------------------------------------------------------------------
- ; -----------------------------------------------------------------------
- ;
- ; Marker Update --- THINK sends this event when it needs the editor to ensure that the
- ; debugger state information is up-to-date. Return the marker
- ; information for EACH open file in an AEDescList composed of the
- ; following structs. See the MiniEdit code for details.
- ;
- ; Event Class: 'KAHL'
- ; Event ID: 'MKUP'
- ; Parameters: none
- ;
- ; struct {
- ; Handle markers, breakpoints, dataviews, lineOffsets, dtvuIDs;
- ; long oldSelStart, oldSelEnd, oldTextLength,
- ; oldLineStart, oldLineEnd, oldNumLines,
- ; newTextLength, newNumLines, newSelEnd;
- ; long refcon;
- ; };
-
- (c:defstruct tc:struct-mkup ((long markers)
- (long breakpoints)
- (long dataviews)
- (long lineOffsets)
- (long dtvuIDs)
- (long oldSelStart)
- (long oldSelEnd)
- (long oldTextLen)
- (long oldLineStart)
- (long oldLineEnd)
- (long oldNumLines)
- (long newTextLen)
- (long newNumLines)
- (long newSelEnd)
- (unsigned-long refCon)))
-
- (defun make-mkup (buffer)
- (let ((old-buffer (current-buffer))
- (mkup (make-string (c:sizeof 'tc:struct-mkup) 0)))
- (set-buffer buffer)
- (if (not tc:have-TPM-data)
- (progn
- (set-buffer old-buffer)
- nil)
- (c:slotset 'tc:struct-mkup mkup 'markers (tc:markers))
- (c:slotset 'tc:struct-mkup mkup 'breakpoints (tc:breakpoints))
- (c:slotset 'tc:struct-mkup mkup 'dataviews (tc:dataviews))
- (c:slotset 'tc:struct-mkup mkup 'lineOffsets (tc:lineOffsets))
- (c:slotset 'tc:struct-mkup mkup 'dtvuIDs (tc:dtvuIDs))
- (c:slotset 'tc:struct-mkup mkup 'oldSelStart tc:oldSelStart)
- (c:slotset 'tc:struct-mkup mkup 'oldSelEnd tc:oldSelEnd)
- (c:slotset 'tc:struct-mkup mkup 'oldTextLen tc:oldTextLen)
- (c:slotset 'tc:struct-mkup mkup 'oldLineStart tc:oldLineStart)
- (c:slotset 'tc:struct-mkup mkup 'oldLineEnd tc:oldLineEnd)
- (c:slotset 'tc:struct-mkup mkup 'oldNumLines tc:oldNumLines)
- (c:slotset 'tc:struct-mkup mkup 'newTextLen (tc:textLen))
- (c:slotset 'tc:struct-mkup mkup 'newNumLines (tc:numLines))
- (c:slotset 'tc:struct-mkup mkup 'newSelEnd (tc:selEnd))
- (c:slotset 'tc:struct-mkup mkup 'refCon buffer)
- (set-buffer old-buffer)
- mkup)))
-
- (AEInstallEventHandler "KAHL" "MKUP" 'tc:do-mkup-event 0 0)
-
- (defun tc:do-mkup-event (event reply refCon)
- (if tc:debug-trace (DebugStr "Emacs TPM code got MKUP event"))
- (condition-case errmsg
- (catch 'panic
- (let* ((old-buffer (current-buffer))
- (mkup-list (make-string sizeof-AEDescList 0))
- (callback-data (encode-long-integer tc:GetLineNum)))
- (throw-err (AEPutParamPtr reply "CLBK" typeChar callback-data (c:sizeof 'long)))
- (throw-err (AECreateList 0 0 0 mkup-list))
- (mapcar (function
- (lambda (x)
- (set-buffer (car x))
- (let ((mkup (make-mkup (car x))))
- (if mkup
- (throw-err
- (AEPutPtr mkup-list 0 typeChar mkup (length mkup)))))))
- (tc:relevant-buffers))
- (throw-err (AEPutParamDesc reply keyDirectObject mkup-list))
- (AEDisposeDesc mkup-list)
- (set-buffer old-buffer)
- noErr))
- (error (DebugStr "Couldn't complete MKUP")
- errAEEventNotHandled)))
-
- ; -----------------------------------------------------------------------
- ; -----------------------------------------------------------------------
- ;
- ; Make LineOffsets --- THINK sends this event when it needs the editor to create a new
- ; lineOffsets array for EACH open file.
- ;
- ; Event Class: 'KAHL'
- ; Event ID: 'OFST'
- ; Parameters: none
-
- ;; long nLines = GetNumLines(TEH); // Create a new lineOffsets array for THINK
- ;; lineOffsets = (short**) NewHandleClear(sizeof(short) * (nLines+1));
- ;; (*lineOffsets)[nLines] = 0x7FFF - nLines;
- ;; return(noErr);
-
- (AEInstallEventHandler "KAHL" "OFST" 'tc:do-ofst-event 0 0)
-
- (defun tc:do-ofst-event (event reply refCon)
- (if tc:debug-trace (DebugStr "Emacs TPM code got OFST event"))
- (condition-case errmsg
- (let* ((old-buffer (current-buffer)))
- (mapcar (function (lambda (x) (set-buffer (car x)) (remake-lineOffsets)))
- (tc:relevant-buffers))
- (set-buffer old-buffer)
- noErr)
- (error (if tc:debug-failures (DebugStr "Couldn't complete OFST"))
- errAEEventNotHandled)))
-
- (defun remake-lineOffsets ()
- (let* ((nLines (tc:numLines))
- (lineOffsets (NewHandleClear (* (c:sizeof 'short) (1+ nLines)))))
- (if (not (zerop (MemError)))
- (MemError)
- (HLock lineOffsets)
- (encode-internal (deref lineOffsets) (* nLines (c:sizeof 'short))
- 'short (- (hex-string-to-int "7fff") nLines))
- (HUnlock lineOffsets)
- ;;; When do we know to dispose of the old lineOffsets?
- (setf-tc:lineOffsets lineOffsets)
- noErr)))
-
- ; -----------------------------------------------------------------------
- ; -----------------------------------------------------------------------
- ;
- ; Failed Find In Next File --- THINK sends the Failed Find In Next File event to tell the
- ; editor that its last FINF request has failed.
- ;
- ; Event Class: 'KAHL'
- ; Event ID: 'NONF'
- ; Parameters: none
-
- (AEInstallEventHandler "KAHL" "NONF" 'tc:do-nonf-event 0 0)
-
- (defun tc:do-nonf-event (event reply refCon)
- (if tc:debug-trace (DebugStr "Emacs TPM code got NONF event"))
- (condition-case errmsg
- (progn
- (beep)
- (message "No more instances found")
- noErr)
- (error (if tc:debug-failures (DebugStr "Couldn't complete NONF"))
- errAEEventNotHandled)))
-
- ; -----------------------------------------------------------------------
- ; -----------------------------------------------------------------------
- ;
- ; OpenProject
- ;
- ; THINK sends the OpenProject event to notify the editor that a project has just been
- ; opened and/or closed. (The direct parameter gives the details.)
- ;
- ; If a project was closed, the user should be asked what to do with any open
- ; sourcefiles that are related to the project: save and close, discard changes and
- ; close, or leave them open. If some of the project's sourcefiles were indeed open,
- ; the user should also be advised to perform a Use Disk the next time he opens the
- ; project.
- ;
- ; If a project was opened, and the editor already has one of the project's sourcefiles
- ; open, it may need to read in the file's marker data now. If so, and the file has
- ; already been modified, the marker data will be out of sync; the best we can do is
- ; revert to the previous saved version.
- ;
- ; See the MiniEdit code for an example of how to handle this event.
- ;
- ; Event Class: 'KAHL'
- ; Event ID: 'OPRJ'
- ; Parameters:
- ;
- ; keyDirectObject (typeShortInteger, required)
- ; 0 == no change (you should never get this)
- ; 1 == a project was opened
- ; 2 == a project was closed
- ; 3 == a project was closed, then a project was opened
-
- (AEInstallEventHandler "KAHL" "OPRJ" 'tc:do-oprj-event 0 0)
-
- (defun tc:do-oprj-event (event reply refCon)
- (if tc:debug-trace (DebugStr "Emacs TPM code got OPRJ event"))
- errAEEventNotHandled)
-
- ; -----------------------------------------------------------------------
- ; -----------------------------------------------------------------------
- ;
- ; CloseProject
- ;
- ; THINK sends the CloseProject event to notify the editor that the current project is
- ; being closed. The keyDirectObject parameter indicates whether the related sourcefiles
- ; should be saved and closed (kAEYes) or closed but not saved (kAENo). If the direct
- ; object is kAEAsk, the user should be asked what to do with any open sourcefiles (an
- ; option should be provided to cancel the project close, also.)
- ; The editor can decide whether to complete or abort THINK's
- ; Close Project command by sending (or failing to send) THINK a CloseProject event in
- ; reply. See the MiniEdit code for an example of how to handle this event.
- ;
- ; Event Class: 'KAHL'
- ; Event ID: 'CPRJ'
- ; Parameters:
- ;
- ; keyDirectObject (typeEnumerated, required)
- ; kAEYes == save and close related sourcefiles;
- ; kAENo == close related sourcefiles, discarding changes;
- ; kAEAsk == ask user what to do with related sourcefiles.
-
- (AEInstallEventHandler "KAHL" "CPRJ" 'tc:do-cprj-event 0 0)
-
- (defun tc:do-cprj-event (event reply refCon)
- (if tc:debug-trace (DebugStr "Emacs TPM code got CPRJ event"))
- (condition-case errmsg
- (catch 'panic
- (let* ((returnedType (make-string 4 0))
- (actualSize (make-string 4 0))
- (yes-no-ask (make-string 4 0)))
- (throw-err (AEGetParamPtr event keyDirectObject typeLongInteger returnedType
- yes-no-ask (c:sizeof 'long) actualSize))
-
- ;;; For now, we simply return noErr, which allows Think to close the
- ;;; project without waiting for a CPRJ event from Emacs.
-
- noErr))
- (error (if tc:debug-failures (DebugStr "Couldn't complete CPRJ"))
- errAEEventNotHandled)))
-